import request from '@/utils/request';
import { DeviceEs, EsPageInfo } from './types';

// 保存设备信息到ES
export function saveDevice(data: DeviceEs) {
  return request({
    url: '/vending/device/es/save',
    method: 'post',
    data
  });
}

// 批量保存设备信息到ES
export function saveBatchDevice(data: DeviceEs[]) {
  return request({
    url: '/vending/device/es/saveBatch',
    method: 'post',
    data
  });
}

// 更新设备信息
export function updateDevice(data: DeviceEs) {
  return request({
    url: '/vending/device/es/update',
    method: 'put',
    data
  });
}

// 删除设备信息
export function deleteDevice(deviceId: string) {
  return request({
    url: `/device/es/${deviceId}`,
    method: 'delete'
  });
}

// 查询指定范围内的设备
export function listNearbyDevices(longitude: number, latitude: number, distance: number = 5) {
  return request({
    url: '/vending/device/es/nearby',
    method: 'get',
    params: {
      longitude,
      latitude,
      distance
    }
  });
}

// 分页查询指定范围内的设备
export function pageNearbyDevices(longitude: number, latitude: number, distance: number = 5, pageNum: number = 1, pageSize: number = 10) {
  return request({
    url: '/vending/device/es/nearby/page',
    method: 'get',
    params: {
      longitude,
      latitude,
      distance,
      pageNum,
      pageSize
    }
  });
}

// 查询圆形范围内的设备
export function listDevicesInCircle(longitude: number, latitude: number, radius: number = 5) {
  return request({
    url: '/vending/device/es/circle',
    method: 'get',
    params: {
      longitude,
      latitude,
      radius
    }
  });
}

// 分页查询圆形范围内的设备
export function pageDevicesInCircle(longitude: number, latitude: number, radius: number = 5, pageNum: number = 1, pageSize: number = 10) {
  return request({
    url: '/vending/device/es/circle/page',
    method: 'get',
    params: {
      longitude,
      latitude,
      radius,
      pageNum,
      pageSize
    }
  });
}
